package com.hua.api.modules.express.rest;


import com.hua.api.core.framework.annotation.AnonymousAccess;
import com.hua.api.core.framework.annotation.TokenCheck;
import com.hua.api.core.framework.util.Result;
import com.hua.api.core.out.showapi.request.ShowApiExpressStatusQueryRequest;
import com.hua.api.core.out.showapi.request.ShowApiGetCompanyRequest;
import com.hua.api.modules.express.service.ExpressOrderService;
import com.hua.api.modules.express.service.dto.ExpressOrderDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/expressOrder")
public class ShowapiExpressOrderController {

    private final ExpressOrderService expressOrderService;

    @AnonymousAccess
    @RequestMapping("/showapi/notify/{expressOrderNo}")
    public ResponseEntity<Map<String,Object>> showApiNotify(@PathVariable String expressOrderNo){
        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        log.info("【物流信息回调】ExpressOrderController.showApiNotify({})",expressOrderNo);
        expressOrderService.showApiNotify(expressOrderNo);
        return  new ResponseEntity<>(map,HttpStatus.OK);
    }

    @AnonymousAccess
    @RequestMapping("/showapi/getcom/{expressOrderNo}")
    // 发物流录入订单号
    public Result expressOrderSave(@PathVariable String expressOrderNo ){
        ShowApiGetCompanyRequest request = new ShowApiGetCompanyRequest();
        request.setNu(expressOrderNo);
        return request.getResult();
    }
    // 
    @RequestMapping("/showapi/create/{orderNo}")
    @TokenCheck(userAgent = "ExpressOrderCreate")
    // 发物流录入订单号
    public Result create(@PathVariable String orderNo, @RequestBody ExpressOrderDto dto){
       expressOrderService.showApiexpressOrderCreate(orderNo,dto);
       return Result.success();
    }

    @AnonymousAccess
    @RequestMapping("/showapi/query/{expressOrderNo}")
    // 发物流录入订单号
    public Result expressOrderQuery(@PathVariable String expressOrderNo){
        ShowApiExpressStatusQueryRequest request = new ShowApiExpressStatusQueryRequest();
        request.setCom("yunda");
        request.setNu(expressOrderNo);
        return request.getResult();
    }





}
